package com.bba.manager.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Component
public class AutoFieldFillHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        strictInsertFill(metaObject,"entryTime", LocalDate.class,LocalDate.now());
        strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
        strictInsertFill(metaObject,"deleted", Integer.class,0);
        strictInsertFill(metaObject,"status", String.class,"0");
        strictInsertFill(metaObject,"payType", Integer.class,0);
        strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());

    }

/**
 * 重写更新填充方法，用于在更新操作时自动填充字段
 * @param metaObject 元数据对象，包含对象的所有属性信息
 */
    @Override
    public void updateFill(MetaObject metaObject) {
    // 调用父类的严格更新填充方法，为指定字段设置当前时间
    // 参数说明：
    // 1. metaObject - 元数据对象
    // 2. "updateTime" - 需要填充的字段名
    // 3. LocalDateTime.class - 字段类型
    // 4. LocalDateTime.now() - 当前时间作为填充值
    strictUpdateFill(metaObject,"updateTime",LocalDateTime.class,LocalDateTime.now());
    }
}
